#pragma once

#include "Protocol.hpp"
#include <iostream>

// client->server 序列化反序列化 Request
// server->client 系列还反序列化 Response
class Cal
{
public:
    Response Execute(Request& req)
    {
        Response resp(0,0);
        switch (req.Oper())
        {
        case '+':
            resp.SetResult(req.X()+req.Y());
            break;
        case '-':
            resp.SetResult(req.X()-req.Y());
            break;
        case '*':
            resp.SetResult(req.X()*req.Y());
            break;
        case '/':
        {
            if(req.Y() == 0)
            {
                resp.SetCode(1);
            }
            else
            {
                resp.SetResult(req.X()/req.Y());
            }
        }
        break;
        case '%':
        {
            if (req.Y() == 0)
            {
                resp.SetCode(2); // 2 mod 0 错误
            }
            else
            {
                resp.SetResult(req.X() % req.Y());
            }
        }
        break;
        default:
            resp.SetCode(3);
            break;
        }
        return resp;
    }

};